package com.yy.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yy.model.UserEntity;
import com.yy.service.UserService;
import com.yy.utils.IgnoreAuth;
import com.yy.utils.ResponseEntity;
import com.yy.validator.Assert;

/**
 * 注册
 * @author 
 * @date 
 */
@RestController
@RequestMapping("/api")
public class ApiRegisterController {
    @Autowired
    private UserService userService;

    /**
     * 注册
     */
    @IgnoreAuth
    @PostMapping("register")
    public ResponseEntity register(@RequestBody UserEntity user){
        Assert.isBlank(user.getMobile(), "手机号不能为空");
        Assert.isBlank(user.getPassword(), "密码不能为空");

        userService.save(user);

        return ResponseEntity.ok();
    }
    /**
     * 手机号注册
     */
    @PostMapping("registerMobile")
    public ResponseEntity registerMobile(String mobile, String password){
        Assert.isBlank(mobile, "手机号不能为空");
        Assert.isBlank(password, "密码不能为空");

        userService.saveMobile(mobile, password);

        return ResponseEntity.ok();
    }
}
